Imports System.Data.OleDb
Imports System.Xml
Imports System.ServiceModel.Syndication


Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.ContentType = "application/rss+xml"
        Dim myrssfeed As New SyndicationFeed
        myrssfeed.Title = TextSyndicationContent.CreatePlaintextContent("Currency Details")
        myrssfeed.Description = TextSyndicationContent.CreatePlaintextContent _
        ("This feed is for global currency details")
        myrssfeed.Links.Add(SyndicationLink.CreateSelfLink _
        (New Uri(okURL("List.aspx"))))
        myrssfeed.Language = "en-us"
        Dim oleDBConn As New OleDbConnection(ConfigurationManager.ConnectionStrings("AllAboutForexDBConnectionString").ConnectionString)
        oleDBConn.Open()
        Dim cmdquery As String = "Select top 5 * from country_currency"
        Dim dbconn = New OleDbCommand(cmdquery, oleDBConn)
        Dim dbread = dbconn.executereader()
        Dim myItems As New List(Of SyndicationItem)
        While dbread.read()
            Dim sitem As New SyndicationItem
            sitem.Title = mkrsslink(dbread("country"))
            sitem.Summary = mkrsstxt(dbread("currency"))
            sitem.Links.Add(mkrsslink(dbread("HyperLink")))
            myItems.add(sitem)
        End While

        myrssfeed.Items = myitems
        Dim feedwriter As XmlWriter = XmlWriter.Create(Response.OutputStream)
        Dim rssformatter = New Rss20FeedFormatter(myrssfeed)
        rssformatter.writeto(feedwriter)
        feedwriter.Close()


    End Sub
    Private Function mkrsslink(ByVal somelocation As String) As SyndicationLink
        Return SyndicationLink.CreateAlternateLink(New Uri(somelocation))
    End Function

    Private Function mkrsstxt(ByVal somestring As String) As TextSyndicationContent
        Return TextSyndicationContent.CreatePlaintextContent(somestring)

    End Function




    Private Function okURL(ByVal urlStr As String)

        Return Request.Url.GetLeftPart(UriPartial.Authority) & ResolveUrl(urlStr)
    End Function

End Class


